def calc_avg():
    total, counter, result = 0, 0, None
    while True:
        num = yield result
        total += num
        counter += 1
        result = total / counter


def main():
    gen = calc_avg()
    # 生成器预激活（升级为协程）
    gen.send(None)
    # next(gen)
    print('平均值：', gen.send(10))
    print('平均值：', gen.send(20))
    print('平均值：', gen.send(30))


if __name__ == '__main__':
    main()
